package lab.gene.service.impl;

import java.util.Date;
import java.util.List;

import lab.gene.dao.GeneDAO;
import lab.gene.dao.GeneQuickChangeDAO;
import lab.gene.pojo.GeneQuickChange;
import lab.gene.pojo.Gene;
import lab.gene.service.GeneQuickChangeService;
import lab.user.dao.UserDAO;
import lab.user.pojo.User;

public class GeneQuickChangeServiceImpl implements GeneQuickChangeService {

	@Override
	public GeneQuickChange getGeneQuickChangeByNameAndType(String geneName,
			String type) {
		// TODO Auto-generated method stub
		GeneQuickChange gqc = null;
		GeneQuickChangeDAO dao = new GeneQuickChangeDAO();
		GeneDAO gdao = new GeneDAO();
		Gene g = gdao.getGene(geneName);
		gqc = dao.getGeneQuickChangeByNameAndType(g, type);
		return gqc;
	}


	@Override
	public void addGeneQuickChange(String geneName, String type, String userName, String comments, Date recordDate){
		// TODO Auto-generated method stub
		UserDAO udao = new UserDAO();
		GeneDAO gdao = new GeneDAO();
		Gene g = gdao.getGene(geneName);
		User u = udao.getUser(userName);
		GeneQuickChange gqc = new GeneQuickChange();
		gqc.setComments(comments);
		gqc.setDateModified(new Date());
		gqc.setGene(g);
		gqc.setRecordDate(recordDate);
		gqc.setType(type);
		gqc.setUser(u);
		GeneQuickChangeDAO dao = new GeneQuickChangeDAO();
		dao.addGeneQuickChange(gqc);

	}

	@Override
	public List<GeneQuickChange> getGeneQuickChangeHistory(String geneName, String type) {
		List<GeneQuickChange> g = null;
		GeneDAO gdao = new GeneDAO();
		Gene gene = gdao.getGene(geneName);
		GeneQuickChangeDAO dao = new GeneQuickChangeDAO();
		g = dao.getGeneQuickChangeHistory(gene, type);
		return g;
	}

}
